

namespace Stee.CAP8.MessageBus.Sample
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Stee.CAP8.MessageBus.Interface.Enums;
    using Stee.CAP8.MessageBus.Interface.Interfaces;
    using Stee.CAP8.MessageBus.Interface.Models;
    using Stee.CAP8.MessageBus.Kafka.Configurations;
    using Stee.CAP8.MessageBus.Kafka.Publisher;
    using Stee.CAP8.MessageBus.Sample.Model;

    public class Program
    {
        private static Person p1 = new Person("QWERTY1", 21);
        private static Person p2 = new Person("QWERTY2", 22);
        private static Person p3 = new Person("QWERTY3", 23);
        private static Person p4 = new Person("QWERTY4", 24);

        public static void Main(string[] args)
        {
            Task t = TestPublish();
            t.Wait();
        }


        private static async Task TestPublish()
        {
            try
            {
                string topic = "first_topic";
                string key = "first_key";
                TopicName topicName = new TopicName(topic, key, MessageType.Event);
                PublisherConfiguration publishConfig = new PublisherConfiguration(new Dictionary<string, string>
                {
                    { "BootstrapServers", "127.0.0.1:9092" },
                    { "Acks", "All" },
                    { "ClientID", "myclient" },
                    { "EnableIdempotence", "true" },
                });

                IPublisher<string> publisher = new PublisherImpl<string>(publishConfig);
                IPublisher<Person> publisherObject = new PublisherImpl<Person>(publishConfig);

                publisher.Publish(topicName, $"Publish w/o properties - The date/time now is: {DateTime.Now}", CancellationToken.None);
                publisherObject.Publish(topicName, p1, CancellationToken.None);

                //publisher.Publish(topicName, $"Publish w/ properties - The date/time now is: {DateTime.Now}", properties, CancellationToken.None);

                //await publisher.PublishAsync(topicName, $"PublishAsync w/o properties - The date/time now is: {DateTime.Now}", CancellationToken.None).ConfigureAwait(false);
                //await publisherObject.PublishAsync(topicName, p3, CancellationToken.None).ConfigureAwait(false);

                //await publisher.PublishAsync(topicName, messageDTO4, properties, CancellationToken.None).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[ERROR] {ex.Message}");
                throw;
            }
        }
    }
}
